﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;

[Serializable]
public class MoveDesc
{
    public bool m_bCombin = false;
    public enum ESpeedDesc
    {
        [Description("匀速")]
        Normal,
        [Description("变速")]
        Acce,
        [Description("固定时间")]
        Time,
    }

    public enum ELifeDesc
    {
        [Description("到目的地")]
        Arrive,
        [Description("经过的最大距离")]
        FlyRealDistance,
        [Description("距出发点的最大距离")]
        FlyFromStart,
        [Description("距发射者的最大距离")]
        FlyFromSender,
        [Description("从创建起的最大时间")]
        Time,
        [Description("追踪专用(时间限制) ")]
        Trace,
    }
    public ESpeedDesc m_eSpeedDesc = ESpeedDesc.Normal;
    public SmartParam m_spSpeedParam = new SmartParam(); // 根据SpeedDesc 不同的解释
    public SmartParam m_spRotateSpeed = new SmartParam();

    public ELifeDesc m_eLifeDesc = ELifeDesc.Arrive;
    public SmartParam m_spLifeParam = new SmartParam(); // 根据LifeDesc 不同的解释
    public float GetSpeed(Vector3 start, Vector3 end)
    {
        switch (m_eSpeedDesc)
        {
            case ESpeedDesc.Time:
                return CommonTools.GetDistance(start, end) / m_spSpeedParam.m_fValue;
                break;
            case ESpeedDesc.Normal:
                break;
            case ESpeedDesc.Acce:
                break;
        }
        return m_spSpeedParam.m_fValue;
    }
    public void DoInitSmartParam(Dictionary<string, string> dic)
    {
        m_spSpeedParam.DoInit(dic);
        m_spRotateSpeed.DoInit(dic);
        m_spLifeParam.DoInit(dic);
    }


}
public class ActionNodeBase : MonoBehaviour
{
    static int VERSION = 1;
    #region 编辑器数据
    public Rect m_rectPos = new Rect(500, 100, 300, 10); // 编辑器里显示的位置
    public bool m_bMin = false;
    public int m_nVersion = 0;
    #endregion
    public string m_strDesc;
    public SmartParam m_spDelayTime = new SmartParam(0);
    public int m_gid;                  // 这个节点的索引id
    public int m_IndexID = -1;         // 索引
    public virtual string DoSave()
    {
        string strData = "";
        return strData;
    }
    public virtual bool OnCombin()
    {
        //try
        //{
        //    DoInitSmartParam(null);
        //}
        //catch(Exception e)
        //{
        //    LogMgr.Instance().LogError("Profabs name = {0} ", gameObject.name );
        //}
        return false;
    }
    public void Start()
    {

    }
    public virtual int GetVersion()
    {
        return -1;
    }
    public bool Combin()
    {
        //if (m_nVersion < GetVersion() )
        {
            if (OnCombin() == false)
                return false;
            m_nVersion = GetVersion();
            return true;
        }
        //return false;
    }


    public virtual void DoInitSmartParam(Dictionary<string, string> dic)
    {
        m_spDelayTime.DoInit(dic);
    }
    public System.Type getFieldType(string fieldName)
    {
        return GetType().GetField(fieldName).FieldType;
    }
    public object getFieldValue(string fieldName)
    {
        if (GetType().GetField(fieldName) == null)
        {
            XKLog.LogError("没有{0}名字的变量，编辑器检查逻辑!", fieldName);
            return null;
        }
        return this.GetType().GetField(fieldName).GetValue(this);
    }
    public void setFieldValue(string fieldName, object val)
    {
        var Ts = this.GetType();
        Ts.GetField(fieldName).SetValue(this, val);
    }
    public virtual void NodeCopy(ActionNodeBase node)
    {

    }
    public virtual void DoDataCheck()
    {
    }
}
